#!/bin/sh

for d in wget python3 grep sed cut; do
	type $d || exit 1
done

# https://fedoraproject.org/wiki/BitmapFontConversion
script=bitmapfonts2otb.py
[ -r "$script" ] || wget "https://ndim.fedorapeople.org/stuff/bitmapfonts2otb/$script" || exit 1

for f in ../bdf/*.bdf; do
    size="$(grep -w ^PIXEL_SIZE "$f" | cut -d' ' -f2)"
    name="$(grep -w ^FAMILY_NAME "$f" | cut -d' ' -f2)"
    name="${name#\"}"
    name="${name%\"}"
    sed "s/^FAMILY_NAME .*/FAMILY_NAME \"$name-$size\"/" "$f" > "$f".tmp
    python3 $script "$f".tmp
    rm "$f".tmp
done
